package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Person;
import com.itheima.edu.info.manager.domain.Student;

import java.util.Scanner;

public class StudentService {
    private  Scanner sc=new Scanner(System.in);
    private  StudentDao studentDao=new StudentDao();

    public boolean AddStudent(Person person) {
           boolean b= studentDao.AddStudent(person);
           return b;
    }
    public boolean isExists(String id){
        Person[] people=studentDao.findAllStudent();
        boolean b=false;
        for (int i = 0; i < people.length; i++) {
            Person person=people[i];
            if (person!=null&&person.getId().equals(id)){
                b=true;
                break;
            }
        }
        return b;
    }

    public Person[] findAllStudent() {
        Person[] people=studentDao.findAllStudent();

        boolean b=false;

        for (int i = 0; i < people.length; i++) {
            Person p=people[i];
            if(p!=null){
                b=true;
                break;
            }
        }
        if (b){
            return people;
        }else {
            return null;
        }
    }

    public void updateStudent(String id, Person newStu) {
        studentDao.updateStudent(id,newStu);
    }

    public void deleteStudent(String id) {
        studentDao.deleteStudent(id);
    }
}
